﻿/*************************************************
网络协议处理通用接口
author：Daixiwei
**************************************************/
using System;

namespace taurus.client
{
    public interface ISocketLayer
    {
        /// <summary>
        /// 连接服务器
        /// </summary>
        void connect();

        /// <summary>
        /// 连接服务器并且验证
        /// </summary>
        /// <param name="validate"></param>
        void connect(ITObject validate);

        /// <summary>
        /// 断开连接
        /// </summary>
        void disconnect();

        /// <summary>
        /// 处理事件
        /// </summary>
        void processEvent();

        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="msg"></param>
        void write(Message msg);

        /// <summary>
        /// get protocol type
        /// </summary>
        /// <returns></returns>
        ConnectionProtocol getProtocol();

        /// <summary>
        /// 设置连接状态回调
        /// </summary>
        /// <param name="onConnect"></param>
        void setOnConnect(Action<SocketCode> onConnect);

        /// <summary>
        /// 设置事件消息回调
        /// </summary>
        /// <param name="onEvent"></param>
        void setOnEvent(Action<Message> onEvent);

        /// <summary>
        /// 网络延时
        /// </summary>
        /// <returns></returns>
        int getAveragePingTime();

        /// <summary>
        /// 获取服务器Session字符
        /// </summary>
        /// <returns></returns>
        string getSession();

        /// <summary>
        /// 设置服务器Session字符
        /// </summary>
        /// <param name="session"></param>
        void setSession(string session);

        void clearResponse();
    }
}
